package com.technology.json;

import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;

import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.google.gson.JsonIOException;
import com.google.gson.JsonSyntaxException;

public class JsonUsing {

	private static Gson gson = new GsonBuilder().create();
	
	public static void main(String[] args) {
		try {
			Developer developer = gson.fromJson(new FileReader("src/com/technology/json/json.txt"), Developer.class);
			System.out.println("Name: " + developer.getName());
			System.out.println("SurName: " + developer.getSurname());
			System.out.println("Exp: " + developer.getExperience());
			developer.setExperience(8);
			developer.setSurname("Petrov");
			FileWriter writer = new FileWriter("src/com/technology/json/json2.txt");
			gson.toJson(developer, writer);
			writer.close();
			
		} catch (JsonSyntaxException | JsonIOException | FileNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
}
